/*
 * Author: 李波(Edwin Lee)
 * Date: 2024-07-07 20:12:38
 * FilePath: /code/C++/PiontAndArray/main.cpp
 * LastEditTime: 2024-08-02 11:06:03
 * version: 1.0
 * Description: 
 */
#include <iostream>

int main()
{
	using namespace std;

	//例子一：指针和数组输出比较
	cout<<"-------------例子一------------------"<<endl;
	int arr1[5] = { 10,12,13,14,15 };
	int* p1 = arr1;
	for (int i = 0; i < 5; i++)//循环输出数组
	{
		cout << "arr1["<<i<<"]:"<<arr1[i] << " "<<endl;
	}
	for (int i = 0; i < 5; i++)//循环输出数组指针
	{
		cout << "p1[" << i << "]:" << p1[i] << " "<<endl;
	}
	for (int i = 0; i < 5; i++)//另一种输出指针方法
	{
		cout << *p1 << endl;
		p1++;
	}


	//例子二：指针和数组的不同点
	cout<<"---------------例子二------------------"<<endl;
	int arr2[3]{ 1,2,3 };//数组可以这么初始化
	int* p2 = arr2;
	char arr3[10] = "hello";
	char* p3 = arr3;

	cout << "size of arr2 is:"<<sizeof(arr2) << endl;//返回数组容量12
	cout << "size of p2 is:" << sizeof(p2) << endl;//返回地址所占的字节数4


	//对于int类型以下四种方法都只会输出地址
	cout<<"----------------------------"<<endl;
	cout << "p2 =" << p2 << endl;
	cout << "arr2 =" << arr2 << endl;
	cout << "(int*)p2 =" << (int*)p2 << endl;
	cout << "(int*)arr2 =" << (int*) arr2 << endl;


	//对于char类型默认输出字符串
	cout<<"----------------------------"<<endl;
	cout << p3 << endl;//对于char类型默认输出字符串
	cout << arr3<< endl;//对于char类型默认输出字符串

	cout << (int*)p3 << endl;//想要输出地址，可以强制转换成int*类型
	cout << (int*)arr3 << endl;//想要输出地址，可以强制转换成int*类型



	return 0;
}